{include file="public/layout" /}
<body>
    {load href="__PUBLIC__/plugins/Ueditor/ueditor.config.js" /}
    {load href="__PUBLIC__/plugins/Ueditor/ueditor.all.min.js" /}
    {load href="__PUBLIC__/plugins/Ueditor/lang/zh-cn/zh-cn.js" /}
  <div class="layui-fluid" id="LAY-component-layer-list">
    <div class="layui-row">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="">
            <form class="layui-form" onsubmit="return false;">
              <div class="bt-close">
                <span class="layui-layer-setwin" ><a onclick="close_this();" class="layui-layer-ico layui-layer-close layui-layer-close1"></a></span>
              </div>
                <div class="layui-tab layui-tab-card">
                  <ul class="layui-tab-title">
                    <li class="layui-this">常规选项</li>
                    <li >高级选项</li>
                  </ul>
                  <div class="layui-tab-content web-system" style="padding:10px 0">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-row layui-col-space15">
                          <div class="layui-col-md12">
                            <div class="layui-card">
                              <div class="layui-card-body" pad15>
                                <div wid100 lay-filter="">
                                
                                  <div class="layui-form-item">
                                    <label class="layui-form-label"><b>*</b>栏目名称</label>
                                    <div class="layui-input-inline">
                                      <input type="text" name="typename" value="" lay-verify="check_typename" class="layui-input">
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">保持唯一性，不可重复</div>
                                    </div>
                                  </div>
                                  <div class="layui-form-item">
                                    <label class="layui-form-label">目录名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" value="" name="dirname" id="dirname" class="layui-input" lay-verify="check_dirname" onkeyup="this.value=this.value.replace(/[^a-zA-Z0-9_]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\[^a-zA-Z0-9_]/g,''));">
                                        <div class="layui-form-inline">留空系统默认全拼音+随机数，仅支持字母、数字、下划线</div>
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">用于伪静态和静态页面生成！</div>
                                    </div>
                                  </div>
                                  <div class="layui-form-item">
                                    <label class="layui-form-label"><b>*</b>内容模型</label>
                                    <div class="layui-input-inline">
                                     <select name="current_channel" id="current_channel" lay-verify="required" lay-filter="current_channel">
                                        {volist name="channeltype_list" id="vo"}
                                        <option value="{$vo.id}" data-nid="{$vo.nid}" {eq name="$current_channel" value="$vo.id"}selected="true"{/eq}>{$vo.title}</option>
                                        {/volist}
                                      </select>
                                      <div class="layui-form-inline2" id="notic_current_channel"></div>
                                    </div>
                                  </div>
                                  {gt name="$parent_id" value="0"}
                                  <div class="layui-form-item">
                                    <label class="layui-form-label">所属栏目</label>
                                    <div class="layui-input-inline">
                                        <div style="padding:6px 0px;">{$ptypename|default=''}</div>
                                    </div>
                                  </div>
                                  {/gt}

                                  <div class="layui-form-item">
                                    <label class="layui-form-label">跳转栏目</label>
                                    <div class="layui-input-inline">
                                      <select id="pointto_id" name="pointto_id">
                                        {$select_pointto_html}
                                      </select>
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">跳转栏目</div>
                                    </div>
                                  </div>


                                  <div class="layui-form-item none">
                                    <label class="layui-form-label">文件保存目录</label>
                                    <div class="layui-input-inline">
                                        <input type="text" value="{$predirpath}" name="dirpath" id="dirpath" class="layui-input" onkeyup="this.value=this.value.replace(/[^0-9a-zA-Z\/-]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^0-9a-zA-Z\/-]/g,''));">
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">生成的文章HTML页面会存放在该目录下</div>
                                    </div>
                                  </div>

                                  <div class="layui-form-item">
                                    <label class="layui-form-label">隐藏栏目</label>
                                    <div class="layui-input-inline w70">
                                        <input type="checkbox" lay-filter="is_hidden" lay-skin="switch" lay-text="是|否">
                                        <input type="hidden" name="is_hidden" value="0" />
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">隐藏之后，不显示在前台页面</div>
                                    </div>
                                  </div>
                                  {include file="field/addonitem" /}
                                  <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <input type="hidden" name="parent_id" id="parent_id" value="{$parent_id|default=''}" />
                                        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-row layui-col-space15">
                          <div class="layui-col-md12">
                            <div class="layui-card">
                              <div class="layui-card-body" pad15>
                                <div wid100 lay-filter="">
                                  <div class="layui-form-item">
                                    <label class="layui-form-label">外部链接</label>
                                    <div class="layui-input-inline w70">
                                        <input type="checkbox" lay-filter="is_part" lay-skin="switch" lay-text="开启|关闭">
                                        <input type="hidden" name="is_part" value="0" />
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">外部连接（在"下方文本框"处填写网址）</div>
                                    </div>
                                  </div>
                                  <div class="layui-form-item none" id="is_part1">
                                    <label class="layui-form-label"><b>*</b>URL网址</label>
                                    <div class="layui-input-inline">
                                      <input type="text" name="typelink" value="" lay-verify="check_typelink" placeholder="http://" class="layui-input">
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">请填写完整外部链接</div>
                                    </div>
                                  </div>
                                  <div class="layui-form-item">
                                    <label class="layui-form-label">英文别名</label>
                                    <div class="layui-input-inline">
                                      <input type="text" name="englist_name" value="" class="layui-input">
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">显示英文名栏目的网站</div>
                                    </div>
                                  </div>
                                  <div class="layui-form-item">
                                    <label class="layui-form-label">栏目图片</label>
                                    <div class="layui-input-inline">
                                        <div class="upload-box">
                                          <div class="upload-img fl">
                                            <div class="icaction none">
                                              <span class="load_images">
                                                 <a href="javascript:void(0);" onclick="BigImages($('#img_litpic').attr('src'));">
                                                 <i class="layui-icon layui-icon-search mr5"></i>查看
                                                 </a>
                                              </span>
                                              <span class="load_images">
                                                <a href="javascript:void(0);" data-inputid="litpic" onclick="DelImages(this);">
                                                <i class="layui-icon layui-icon-delete mr5"></i>删除
                                                </a>
                                              </span>
                                            </div>
                                            <div class="cover-bg none"></div>
                                            <img id="img_litpic" src="{:get_default_pic()}">
                                          </div>
                                          <div class="upload-right fl">
                                            <button class="layui-btn test-upload-demoMore layui-btn-primary layui-btn-sm fl mb10 mr5" lay-data="{number:1,ey_inputId:'litpic',ey_savepath:'allimg'}"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                                            <button class="layui-btn layui-btn-sm layui-btn-primary layui-btn-sm fl mb10" onClick="GetPictureFolder(1,'litpic');"><i class="layui-icon">&#xe64a;</i>图库</button>
                                            <input name="litpic" id="litpic" placeholder="图片地址" value="" class="layui-input">
                                          </div>
                                        </div>
                                    </div>
                                  </div>
                                  <div class="layui-form-item" id="dl_templist">
                                    <label class="layui-form-label" for="templist"><b>*</b>列表模板</label>
                                    <div class="layui-input-inline">
                                       <select name="templist" id="templist" lay-verify="check_templist">
                                      </select>
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">列表模板命名规则：<br/>lists_<font class="font_nid">模型标识</font>.htm<br/>lists_<font class="font_nid">模型标识</font>_自定义.htm</div>
                                    </div>
                                     <div class="layui-input-inline layadmin-layer-demo">
                                       <a class="layui-btn layui-btn-sm" data-value="lists" data-type="newtpl">新建模板</a>
                                    </div>
                                  </div>
                                  <div class="layui-form-item" id="dl_tempview">
                                    <label class="layui-form-label" for="tempview"><b>*</b>文档模板</label>
                                    <div class="layui-input-inline">
                                       <select name="tempview" id="tempview" lay-verify="check_tempview">
                                      </select>
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">文档模板命名规则：<br/>view_<font class="font_nid">模型标识</font>.htm<br/>view_<font class="font_nid">模型标识</font>_自定义.htm</div>
                                    </div>
                                     <div class="layui-input-inline layadmin-layer-demo">
                                       <a class="layui-btn layui-btn-sm" data-value="view" data-type="newtpl">新建模板</a>
                                    </div>
                                  </div>
                                  <div class="layui-form-item">
                                    <label class="layui-form-label">SEO标题</label>
                                    <div class="layui-input-inline">
                                      <input type="text" name="seo_title" value="" class="layui-input">
                                    </div>
                                  </div>                        
                                  <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">SEO关键字</label>
                                    <div class="layui-input-inline">
                                      <textarea name="seo_keywords" class="layui-textarea"></textarea>
                                    </div>
                                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                      <div class="layui-form-inline2 ey_helptips_txt">多个关键词请用英文逗号（,）隔开，建议3到5个关键词。</div>
                                    </div>
                                  </div>
                                  <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">SEO描述</label>
                                    <div class="layui-input-inline">
                                      <textarea name="seo_description" class="layui-textarea"></textarea>
                                    </div>
                                  </div>
                                  <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <input type="hidden" name="grade" id="grade" value="{$grade|default='0'}">
                                        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                     </div>
                    
                    </div>
                  </div>
                </div>
            </form>
          </div>
        </div>
     </div>
  </div>

  <script>
    
    $(document).ready(function(){
        // 鼠标事件，加载查看大图和删除图片
        $(".upload-img").live('mouseover', function(){
            $(this).find('div.icaction').show();
            $(this).find('div.cover-bg').show();
        }).live('mouseout', function(){
            $(this).find('div.icaction').hide();
            $(this).find('div.cover-bg').hide();
        });
    });

  var formNew;
  layui.config({
    base: '__SKIN__/' //静态资源所在路径
    ,version: '{$version}'
  }).extend({
    index: 'lib/index', //主入口模块
  }).use(['index', 'form', 'set'], function(){
    var $ = layui.$
    ,element = layui.element
    ,router = layui.router()
    ,layer = layui.layer
    ,form = formNew = layui.form;

    element.render();

    var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

    var templateList = {$templateList|json_encode};
    ajax_get_template();

    form.verify({
      check_typename: function(value, item){
        if(value == '' || undefined == value){
            tabchange(0)
            return '必填项不能为空';
        }
      }
      ,check_dirname: function(value, item){
        var patrn = /^\d+$/;
        if (patrn.test(value) == true) {
            tabchange(0)
            return '目录名称不能为纯数字！';
        }
      }
      ,check_typelink: function(value, item){ //value：表单的值、item：表单的DOM对象
        if ($('input[name=is_part]').val() == 1) {
            if(value == ''){
                tabchange(1);
                return '外部链接不能为空！';
            }
        }
      }
      ,check_templist: function(value, item){
        if(value == '' || undefined == value){
            tabchange(1)
            return '请选择列表模板';
        }
      }
      ,check_tempview: function(value, item){
        var channel = parseInt($('#current_channel').find('option:selected').val());
        var js_allow_channel_arr = {$js_allow_channel_arr};
        if($('#tempview').val() == '' && $.inArray(channel, js_allow_channel_arr) != -1){
            tabchange(1)
            return '请选择文档模板';
        }
      }
    }); 

    function tabchange(tabIndex)
    {
        var tabObj = $('div.layui-tab ul.layui-tab-title');
        tabObj.find('li').each(function(){
            $(this).removeClass('layui-this');
        });
        $(tabObj.find('li').get(tabIndex)).addClass('layui-this');
        $('.layui-tab-item').removeClass('layui-show');
        $($('.layui-tab-item').get(tabIndex)).addClass('layui-show');
    }

    // 监听开关
    form.on('switch', function(data){
      var elemId = data.elem.attributes['lay-filter']['nodeValue'];
      if (data.elem.checked) {
        this.value = 1;
      } else {
        this.value = 0;
      }
      $("input[name='"+elemId+"']").val(this.value);
    });

    // 监听开关
    form.on('switch(is_part)', function(data){
      var elemId = data.elem.attributes['lay-filter']['nodeValue'];
      if (data.elem.checked) {
        this.value = 1;
        $('#is_part1').show();
      } else {
        this.value = 0;
        $('#is_part1').hide();
      }
      $("input[name='"+elemId+"']").val(this.value);
    });

    form.on('select(current_channel)', function(data){
        ajax_get_template();
    });

    /* 触发事件 */
    var active = {
      newtpl: function(){
        var type = $(this).data('value');
        var nid = $('#current_channel').find('option:selected').attr('data-nid');
        var url = "{:url('Arctype/ajax_newtpl')}";
        if (url.indexOf('?') > -1) {
            url += '&';
        } else {
            url += '?';
        }
        url += 'type='+type+'&nid='+nid;

        if ('lists' == type) {
            var title = '新建列表模板';
        } else {
            var title = '新建文档模板';
        }
        //iframe窗
        var iframes = layer.open({
            type: 2,
            title: title,
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            // maxmin: true, //开启最大化最小化按钮
            area: ['90%', '90%'],
            content: url
        });
      }

    };
    $('#LAY-component-layer-list .layadmin-layer-demo .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] && active[type].call(this);
    });

    //监听提交
    form.on('submit(formSubmit)', function(data){
        var load = layer_loading();
        data.field._ajax = 1;
        $.ajax({
            type : 'post',
            url : "{:url('Arctype/add')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                layer.close(load); //关闭loading
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                        parent.gourl(res.url);
                    });
                }else{
                    showErrorMsg(res.msg);
                }
            },
            error: function(e){
                layer.close(load); //关闭loading
                showErrorAlert();
            }
        });
        return false;
    });

    /*根据模型ID获取模板文件名*/
    function ajax_get_template() {
        var obj = $('#current_channel');
        var channel = parseInt($(obj).find('option:selected').val());
        var js_allow_channel_arr = {$js_allow_channel_arr};
        $('#notic_current_channel').html('');

        // 重新定义模板变量，专用于新建模板功能
        $.ajax({
            url: "{:url('Arctype/ajax_getTemplateList')}",
            type: 'GET',
            dataType: 'JSON',
            data: {_ajax:1},
            success: function(res){
                if (res.code == 1) {
                    templateList = res.data.templateList;
                }
            }
        });
        // end

        if (templateList[channel] == undefined || templateList[channel] == '') {
            showErrorMsg('模板文件不存在！');
            return false;
        } else if (templateList[channel]['msg'] != '') {
            $('#notic_current_channel').html(templateList[channel]['msg']);
        }

        $('#templist').html(templateList[channel]['lists']);
        if ($.inArray(channel, js_allow_channel_arr) == -1) {
            if (channel == 6) {
                $('#dl_templist').find('label[for=templist]').html('<b>*</b>单页模板');
            }
            $('#dl_tempview').hide();
        } else {
            $('#dl_templist').find('label[for=templist]').html('<b>*</b>列表模板');
            $('#dl_tempview').show();
        }
        $('#tempview').html(templateList[channel]['view']);

        $('.font_nid').html(templateList[channel]['nid']);

        form.render();

        return false;
    }
    /*--end*/

  });

    function formRender()
    {
        formNew.render();
    }
  </script>
{include file="public/footer" /}
